<template>
  <div class="login-style">
    <el-input v-model="name" placeholder="请输入账号"></el-input>
    <el-input v-model="password" placeholder="请输入密码"></el-input>
    <el-button type="primary" @click="login">登录</el-button>
  </div>
</template>

<script>
export default {
  name: 'hello',
  data () {
    return {
      name: '',
      password: ''
    }
  },
  methods: {
    login () {
      console.log(window.location.href.split('?')[1], 'href')
      let path = window.location.href.split('?')[1]
      console.log(path, 'path')
      let params = {
        name: this.name,
        password: this.password,
        redirectPath: path
      }
      console.log(params, 'params')
      this.$axios.post('/api/auth/login', params).then((response) => {
        localStorage.setItem('token', response.data)
        localStorage.setItem('token_exp', new Date().getTime())
        console.log(response.data.code, 'code')
        if (response.data.code) {
          this.$notify({
            title: '成功',
            message: response.data.message,
            type: 'success'
          })
          window.location.href = '/home'
        } else {
          this.$notify({
            title: '警告',
            message: response.data.message,
            type: 'warning'
          })
        }
      }).catch((reject) => {
        console.log(reject)
      })
    }
  }
}
</script>

<style scoped>
  .login-style {
    margin:0 42%;
  }
  .el-input {
    padding-bottom: 16px;
  }
</style>
